/**
 * Project Name:emm-website
 * File Name:FXProjectController.java
 * Package Name:com.emm.yixun.website.controller.estate
 * Date:2017年6月28日下午4:55:59
 * Copyright (c) 2017, www.yixunInfo.com All Rights Reserved.
 *
 */

package com.emm.yixun.website.controller.estate;

import java.util.ArrayList;
import java.util.Date;
import java.util.List;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import net.sf.json.JSONArray;
import net.sf.oval.ConstraintViolation;
import net.sf.oval.Validator;

import org.activiti.engine.RepositoryService;
import org.activiti.engine.repository.ProcessDefinition;
import org.activiti.engine.repository.ProcessDefinitionQuery;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import com.alibaba.fastjson.JSON;
import com.emm.yixun.common.constant.SysConstants;
import com.emm.yixun.common.enums.ProcessTypeEnums;
import com.emm.yixun.common.model.Area;
import com.emm.yixun.common.model.Merchant;
import com.emm.yixun.common.model.Project;
import com.emm.yixun.common.model.ProjectImg;
import com.emm.yixun.common.model.ProjectInfo;
import com.emm.yixun.common.model.ProjectProcdef;
import com.emm.yixun.common.model.ProjectSetting;
import com.emm.yixun.common.model.Role;
import com.emm.yixun.common.model.User;
import com.emm.yixun.common.model.dto.AreaDto;
import com.emm.yixun.common.model.dto.ProjectDto;
import com.emm.yixun.common.model.dto.ProjectImgDto;
import com.emm.yixun.common.model.dto.ProjectInfoDto;
import com.emm.yixun.common.model.dto.ProjectProcdefDto;
import com.emm.yixun.common.model.dto.ProjectSettingDto;
import com.emm.yixun.common.model.dto.RoleDto;
import com.emm.yixun.common.model.dto.SalesGroupDto;
import com.emm.yixun.common.model.dto.SalesGroupUserDto;
import com.emm.yixun.common.model.dto.UserDto;
import com.emm.yixun.common.model.enums.DeliveryStatusEnum;
import com.emm.yixun.common.model.enums.ItemTypesEnum;
import com.emm.yixun.common.model.enums.ProjectTypeEnum;
import com.emm.yixun.common.model.enums.RenovationTypeEnums;
import com.emm.yixun.common.model.enums.SalesStatusEnum;
import com.emm.yixun.common.model.enums.TenementTypeEnum;
import com.emm.yixun.common.response.Response;
import com.emm.yixun.common.response.ResponseList;
import com.emm.yixun.common.utils.BeanUtil;
import com.emm.yixun.estate.service.ProjectImgServiceFacade;
import com.emm.yixun.estate.service.ProjectInfoServiceFacade;
import com.emm.yixun.estate.service.ProjectProcdefServiceFacade;
import com.emm.yixun.estate.service.ProjectServiceFacade;
import com.emm.yixun.estate.service.ProjectSettingServiceFacade;
import com.emm.yixun.marketing.service.SalesGroupUserServiceFacade;
import com.emm.yixun.system.service.AreaServiceFacade;
import com.emm.yixun.system.service.MerchantServiceFacade;
import com.emm.yixun.system.service.RoleServiceFacade;
import com.emm.yixun.system.service.UserServiceFacade;
import com.emm.yixun.website.common.ajax.AjaxRes;
import com.emm.yixun.website.common.utils.base.Const;
import com.emm.yixun.website.common.utils.security.ShiroUtil;
import com.emm.yixun.website.controller.base.BaseController;
import com.emm.yixun.website.vo.estate.ProjectInfoVo;
import com.emm.yixun.website.vo.estate.ProjectSettingVo;
import com.emm.yixun.website.vo.estate.ProjectVo;

/**
 * ClassName:FXProjectController <br/>
 * Reason: 丰策业务 ADD REASON. <br/>
 * Date: 2017年6月28日 下午4:55:59 <br/>
 * 
 * @author Administrator
 * @version
 * @since JDK 1.6
 * @see
 */

@Controller
@RequestMapping("/FC/estate/project")
public class FCProjectController extends BaseController<Object> {

    @Autowired
    private RoleServiceFacade roleServiceFacade;

    @Autowired
    private UserServiceFacade userServiceFacade;

    @Autowired
    private ProjectServiceFacade projectServiceFacade;

    @Autowired
    private AreaServiceFacade areaServiceFacade;

    @Autowired
    private ProjectImgServiceFacade projectImgServiceFacade;

    @Autowired
    private ProjectSettingServiceFacade projectSettingServiceFacade;

    @Autowired
    private ProjectInfoServiceFacade projectInfoServiceFacade;

    @Autowired
    private SalesGroupUserServiceFacade salesGroupUserServiceFacade;
    
    @Autowired
    private ProjectProcdefServiceFacade projectProcdefServiceFacade;
    
    @Autowired
    private MerchantServiceFacade merchantServiceFacade;

    
    @Autowired
    private RepositoryService repositoryService;
    @RequestMapping(value = "/toFCAdd")
    public String toAdd(HttpServletRequest httpServletRequest,
	    HttpServletResponse httpServletResponse, ModelMap map, Long id) {

	// 产品类型
	map.put("projectTypes", ProjectTypeEnum.values());

	// 项目类型
	map.put("itemTypes", ItemTypesEnum.values());
	// 交付情况
	map.put("deliveryStatusEnums", DeliveryStatusEnum.values());
	// 销售情况
	map.put("salesStatusEnums", SalesStatusEnum.values());
	// 装修标准
	map.put("renovationTypeEnums", RenovationTypeEnums.values());
	User user = ShiroUtil.getCurrentUser();
	String[] roleNames = SysConstants.PROJECT_ROLE_NAME_FC;
	for (int i = 0; i < roleNames.length; i++) {
	    RoleDto roleDto = new RoleDto();
	    roleDto.setMerchantId(user.getMerchantId());
	    roleDto.setRoleName(roleNames[i]);
	    ResponseList<Role> roleResponseList = roleServiceFacade
		    .findByDto(roleDto);
	    ArrayList<User> userList = new ArrayList<User>();
	    if (roleResponseList.isSuccess()
		    && null != roleResponseList.getEntity()) {
			for (Role role : roleResponseList.getEntity()) {
			    UserDto dto = new UserDto();
			    dto.setMerchantId(user.getMerchantId());
			    dto.setUserStatus("0");
			    dto.setRoleId(role.getId());
			    ResponseList<User> responseList = userServiceFacade
				    .findByDto(dto);
			    if (responseList.isSuccess()
				    && null != responseList.getEntity()) {
			    	userList.addAll(responseList.getEntity());
			    }
			}
	    }
	    if (i == 0) {
	    	map.put("generalManager", userList);
	    } else if (i == 1) {
	    	map.put("projectLeader", userList);
	    } else if (i == 2) {
	    	map.put("saleLeader", userList);
	    } else if (i == 3) {
	    	map.put("fieldLeader", userList);
	    } else if (i == 4) {
	    	map.put("maLeader", userList);
	    } else if (i == 5) {
	    	map.put("financeLeader", userList);
	    }else if (i == 6) {
	    	map.put("areaLeader", userList);
	    }
	}

	// 物业类型
	map.put("tenementTypeEnums", TenementTypeEnum.values());

	AreaDto areaDto = new AreaDto();
	areaDto.setParentId(Long.valueOf(0));
	ResponseList<Area> responseAreaList = areaServiceFacade
		.findByDto(areaDto);
	if (responseAreaList.isSuccess()
		&& null != responseAreaList.getEntity()) {
	    map.put("areas", responseAreaList.getEntity());
	} else {
	    map.put("areas", new ArrayList<Area>());
	}
	Response<Project> response = projectServiceFacade.findById(id);
	if (response.isSuccess() && response.getEntity() != null) {
	    map.put("project", response.getEntity());
	    // 查询图片
	    ProjectImgDto projectImgDto = new ProjectImgDto();
	    projectImgDto.setProjectId(id);
	    projectImgDto.setDelFlag("0");
	    ResponseList<ProjectImg> responseListImg = projectImgServiceFacade
		    .findByDto(projectImgDto);
	    if (responseListImg.isSuccess()
		    && null != responseListImg.getEntity()) {
		map.put("imgList", responseListImg.getEntity());
	    }

	    ProjectInfoDto projectInfoDto = new ProjectInfoDto();
	    projectInfoDto.setProjectId(id);
	    ResponseList<ProjectInfo> responseProjectInfo = projectInfoServiceFacade
		    .findByDto(projectInfoDto);
	    if (responseProjectInfo.isSuccess()
		    && null != responseProjectInfo.getEntity()
		    && responseProjectInfo.getEntity().size() > 0) {
		map.put("projectInfo", responseProjectInfo.getEntity().get(0));
	    }

	    ProjectSettingDto projectSettingDto = new ProjectSettingDto();
	    projectSettingDto.setProjectId(id);
	    ResponseList<ProjectSetting> setResponseList = projectSettingServiceFacade
		    .findByDto(projectSettingDto);
	    if (setResponseList.isSuccess()
		    && null != setResponseList.getEntity()
		    && setResponseList.getEntity().size() > 0) {
		map.put("projectSetting", setResponseList.getEntity().get(0));
	    } else {
		map.put("projectSetting", new ProjectSetting());
	    }

	}
	return "/estate/projectFC/form";

    }

    @RequestMapping(value = "add", method = RequestMethod.POST)
    @ResponseBody
    public AjaxRes add(ProjectVo projectVo, ProjectInfoVo projectInfoVo,
	    ProjectSettingVo projectSettingVo, Long projectInfoId,
	    Long settingId, Long imgId, String otherProjectType) {
	AjaxRes ar = getAjaxRes();
	/*
	 * 1.判断权限2.调用新增接口3.返回信息
	 */
	// 总经理
	if (null == projectSettingVo.getGeneralManager()) {
	    projectSettingVo.setGeneralManager(null);
	}
	// 项目总
	if (null == projectSettingVo.getProjectLeader()) {
	    projectSettingVo.setProjectLeader(null);
	}
	// 经济总
	if (null == projectSettingVo.getSaleLeader()) {
	    projectSettingVo.setSaleLeader(null);
	}

	// 销售经理
	if (null == projectSettingVo.getFieldLeader()) {
	    projectSettingVo.setFieldLeader(null);
	}

	// 财务经理
	if (null == projectSettingVo.getFinanceLeader()) {
	    projectSettingVo.setFinanceLeader(null);
	}
	// 销管经理
	if (null == projectSettingVo.getMaLeader()) {
	    projectSettingVo.setMaLeader(null);
	}
	//行政总监
	if (null == projectSettingVo.getAreaLeader()) {
	    projectSettingVo.setAreaLeader(null);
	}
	/*
	String authStr = "estate:project:add";
	if (null != projectInfoId) {
	    authStr = "estate:project:edit";
	}
	*/
	if (true/*
		 * ar.setNoAuth(doSecurityIntercept(Const.RESOURCES_TYPE_BUTTON,
		 * authStr))
		 */) {
	    try {
		projectInfoVo.setId(projectInfoId);
		projectSettingVo.setId(settingId);
		User user = ShiroUtil.getCurrentUser();
		if (StringUtils.isNotBlank(otherProjectType)) {
		    // 将其它产品类型存到remark字段中，避免新加字段
		    projectVo.setRemark(otherProjectType);
		}
		projectVo.setMerchantId(user.getMerchantId());
		projectVo.setUserCode(user.getUserCode());
		projectVo.setCreateUserId(user.getId());
		projectVo.setDelFlag("0");
		projectVo.setUpdateUserId(user.getId());
		projectVo.setUpdateTime(new Date());

		projectInfoVo.setMerchantId(user.getMerchantId());
		projectInfoVo.setUserCode(user.getUserCode());
		projectInfoVo.setCreateUserId(user.getId());
		projectInfoVo.setDelFlag("0");
		projectInfoVo.setUpdateUserId(user.getId());
		projectInfoVo.setUpdateTime(new Date());

		projectSettingVo.setMerchantId(user.getMerchantId());
		projectSettingVo.setUserCode(user.getUserCode());
		projectSettingVo.setCreateUserId(user.getId());
		projectSettingVo.setDelFlag("0");
		projectSettingVo.setUpdateUserId(user.getId());
		projectSettingVo.setUpdateTime(new Date());

		Validator validator = new Validator();
		List<ConstraintViolation> projectVoError = validator
			.validate(projectVo);
		List<ConstraintViolation> projectInfoVoError = validator
			.validate(projectInfoVo);
		List<ConstraintViolation> projectSettingError = validator
			.validate(projectSettingVo);
		if (projectVoError != null && projectVoError.size() > 0) {
		    ar.setFailMsg(projectVoError.get(0).getMessage());
		    return ar;
		}
		if (projectInfoVoError != null && projectInfoVoError.size() > 0) {
		    ar.setFailMsg(projectInfoVoError.get(0).getMessage());
		    return ar;
		}
		if (projectSettingError != null
			&& projectSettingError.size() > 0) {
		    ar.setFailMsg(projectSettingError.get(0).getMessage());
		    return ar;
		}

		ProjectDto projectDto = BeanUtil.convert2T(new ProjectDto(),
			projectVo);
		ProjectInfoDto projectInfoDto = BeanUtil.convert2T(
			new ProjectInfoDto(), projectInfoVo);
		ProjectSettingDto projectSettingDto = BeanUtil.convert2T(
			new ProjectSettingDto(), projectSettingVo);
		// 保存项目信息
		Response<ProjectDto> response = projectServiceFacade.save(
			projectDto, projectInfoDto, projectSettingDto, null);
		if (!response.isSuccess()) {
		    ar.setFailMsg(response.getResultMessage());
		    return ar;
		}
		// 保存图片
		saveProjectImg(user, response.getEntity(), projectVo);

		// 新增销售组
		projectSettingDto.setProjectCode(response.getEntity()
			.getProjectCode());
		projectSettingDto.setProjectId(response.getEntity().getId());
		initSalesGroup(user, projectSettingDto);
		// 初始化流程
		if (null == projectVo.getId()) {
		    // 项目新增初始化审批流程(ym)
		    initProcessDef(response.getEntity().getId(), response
			    .getEntity().getProjectCode(), user);
		}

		ar.setSucceedMsg(projectVo.getId() == null ? Const.SAVE_SUCCEED
			: Const.UPDATE_SUCCEED);
	    } catch (Exception e) {
		logger.error(e.toString(), e);
		ar.setFailMsg(e.getMessage());
	    }
	}
	return ar;
    }

    private void saveProjectImg(User user, ProjectDto projectDto,
	    ProjectVo projectVo) {
	if (null == projectDto)
	    return;
	if (null == projectVo)
	    return;
	// 删除这个项目下面所有的图片
	if (projectDto.getId() != null) {
	    ProjectImgDto dto = new ProjectImgDto();
	    dto.setProjectId(projectDto.getId());
	    dto.setProjectImgCode("projectCode");
	    ResponseList<ProjectImg> list = projectImgServiceFacade
		    .findByDto(dto);
	    if (list.isSuccess() && list.getEntity() != null) {
		for (ProjectImg img : list.getEntity()) {
		    projectImgServiceFacade.deleteByPrimaryKey(img.getId());
		}
	    }
	}
	Long projectId = projectDto.getId();
	String projectCode = projectDto.getProjectCode();
	// 项目logo
	saveImg(user, projectId, projectCode, projectVo.getLogoUrl(), "1");
	// 总平面图
	saveImg(user, projectId, projectCode, projectVo.getPlaneUrl(), "2");
	// 周边配套图
	saveImg(user, projectId, projectCode, projectVo.getPeripheryUrl(), "3");
	// 交通图
	saveImg(user, projectId, projectCode, projectVo.getTrafficUrl(), "4");
	// 实景图
	saveImg(user, projectId, projectCode, projectVo.getRealUrl(), "5");
	// 样板图
	saveImg(user, projectId, projectCode, projectVo.getModelUrl(), "6");
	// 效果图
	saveImg(user, projectId, projectCode, projectVo.getEffectUrl(), "7");
    }

    private void saveImg(User user, Long projectId, String projectCode,
	    String imgUrl, String type) {
	if (StringUtils.isBlank(imgUrl))
	    return;
	String[] urls = imgUrl.split(";");
	if (null == urls || urls.length <= 0)
	    return;
	for (int i = 0; i < urls.length; i++) {
	    ProjectImgDto projectImgDto = new ProjectImgDto();
	    projectImgDto.setUserCode(user.getUserCode());
	    projectImgDto.setMerchantId(user.getMerchantId());
	    projectImgDto.setDelFlag("0");
	    projectImgDto.setAccessCode(projectCode);
	    projectImgDto.setLargeUrl(urls[i]);
	    projectImgDto.setNormalUrl(urls[i]);
	    projectImgDto.setSmallUrl(urls[i]);
	    projectImgDto.setProjectImgType(type);
	    projectImgDto.setProjectCode(projectCode);
	    projectImgDto.setAccessCode(projectCode);
	    projectImgDto.setProjectId(projectId);
	    projectImgDto.setCreateUserId(user.getId());
	    projectImgDto.setProjectImgCode("projectCode");
	    projectImgServiceFacade.save(projectImgDto);
	}

    }

    private void initSalesGroup(User user, ProjectSettingDto projectSettingDto)
	    throws Exception {
	// 组装销售组
	SalesGroupDto dto = new SalesGroupDto();
	dto.setProjectId(projectSettingDto.getProjectId());
	dto.setProjectCode(projectSettingDto.getProjectCode());
	dto.setName("管理组");
	dto.setSort(0);
	dto.setStatus("0");
	dto.setSaleAttr("1");
	dto.setRemark("新建项目,初始化管理组");
	dto.setOriginal("project");
	// 组装销售组成员
	List<SalesGroupUserDto> userDto = new ArrayList<SalesGroupUserDto>();
	// 公司总经理
	SalesGroupUserDto sgu0 = new SalesGroupUserDto();
	sgu0.setUserId(projectSettingDto.getProjectLeader());
	sgu0.setStatus("0");
	sgu0.setRemark("新建项目,分公司总经理");
	// 项目负责人
	SalesGroupUserDto sgu1 = new SalesGroupUserDto();
	sgu1.setUserId(projectSettingDto.getSaleLeader());
	sgu1.setStatus("0");
	sgu1.setRemark("新建项目,项目总监");
	// 销售经理
	SalesGroupUserDto sgu2 = new SalesGroupUserDto();
	sgu2.setUserId(projectSettingDto.getFieldLeader());
	sgu2.setStatus("0");
	sgu2.setRemark("新建项目,初始化销售经理");
	// 销售主管
	SalesGroupUserDto sgu3 = new SalesGroupUserDto();
	sgu3.setUserId(projectSettingDto.getMaLeader());
	sgu3.setStatus("0");
	sgu3.setRemark("新建项目,初始化销售经理");
	// 财务负责人
	SalesGroupUserDto sgu4 = new SalesGroupUserDto();
	sgu4.setUserId(projectSettingDto.getFinanceLeader());
	sgu4.setStatus("0");
	sgu4.setRemark("新建项目,财务");
	
	
	SalesGroupUserDto sgu5 = new SalesGroupUserDto();
	sgu5.setUserId(projectSettingDto.getGeneralManager());
	sgu5.setStatus("0");
	sgu5.setRemark("新建项目,总经理");
	
	if (isAdd(userDto, sgu0))
	    userDto.add(sgu0);
	if (isAdd(userDto, sgu1))
	    userDto.add(sgu1);
	if (isAdd(userDto, sgu2))
	    userDto.add(sgu2);
	if (isAdd(userDto, sgu3))
	    userDto.add(sgu3);
	if (isAdd(userDto, sgu4))
	    userDto.add(sgu4);
	if (isAdd(userDto, sgu5))
	    userDto.add(sgu5);
	Response<Integer> response = salesGroupUserServiceFacade
		.batchGroupUser(user, dto, userDto);
	if (!response.isSuccess()) {
	    throw new RuntimeException(response.getResultMessage());
	}

    }

    private boolean isAdd(List<SalesGroupUserDto> userDto,
	    SalesGroupUserDto salesGroupUserDto) {
	if (salesGroupUserDto.getUserId() == null)
	    return false;
	for (SalesGroupUserDto sgud : userDto) {
	    if (sgud.getUserId().compareTo(salesGroupUserDto.getUserId()) == 0) {
		return false;
	    }
	}
	return true;
    }

    private void initProcessDef(Long projectId, String projectCode, User user) {
	try {
		//商户自定义流程前缀
		String procDefinedPrefix = getProcDefinedPrefix(user);
	    for (ProcessTypeEnums pte : ProcessTypeEnums.values()) {
			ProjectProcdefDto ppdQuery = new ProjectProcdefDto();
			ppdQuery.setMerchantId(user.getMerchantId());
			ppdQuery.setProjectId(projectId);
			ppdQuery.setProcType(pte.getNo());
			ResponseList<ProjectProcdef> ppList = projectProcdefServiceFacade
				.findByDto(ppdQuery);
			if (ppList.isSuccess() && null != ppList.getEntity()
				&& ppList.getEntity().size() > 0) {
			    continue;
			}
			
			//查询流程,获取前缀信息
			String pteNo = pte.getNo();
			String pteInit = pte.getInit();
			//petInit=1为定制化流程
			if(!"0".equals(pteInit)){
				continue;
			}
			//新的流程类型
			String newPteKey = "";
			//新流程类型对应的流程key
			//由于流程Key可能与原定义key不一致(主要原因为定义的字段太长了,不得不改),名字给修改过.
			//需重新获取一遍.
			String newPteNo = pteNo;
			if(StringUtils.isNotEmpty(procDefinedPrefix)){
				newPteKey = procDefinedPrefix + pteNo;
				ProcessTypeEnums ptEnums = ProcessTypeEnums.getByNo(newPteKey);
				if(null == ptEnums){
					continue;
				}
				newPteNo = ptEnums.getDes();
			}
			
			ProcessDefinitionQuery query = repositoryService
				.createProcessDefinitionQuery();
			List<ProcessDefinition> processDefinitionList = query
				.processDefinitionKey(newPteNo).list();
			if (null == processDefinitionList
				|| processDefinitionList.size() == 0) {
			    continue;
			}
			ProjectProcdefDto ppd = new ProjectProcdefDto();
			ppd.setMerchantId(user.getMerchantId());
			ppd.setUserCode(user.getUserCode());
			ppd.setProjectId(projectId);
			ppd.setAccessCode(projectCode);
			ppd.setCreateUserId(user.getId());
			ppd.setUpdateTime(new Date());
			ppd.setDelFlag("0");
			ProcessDefinition processDefinition = processDefinitionList.get(0);
			ppd.setProcKey(processDefinition.getKey());
			ppd.setProcdefId(processDefinition.getId());
			ppd.setProcName(processDefinition.getName());
			ppd.setProcType(pte.getNo());
			projectProcdefServiceFacade.save(ppd);
	    }
	} catch (Exception e) {
	    logger.error(e.toString(), e);
	}

    }
    @RequestMapping(value = "index")
    public String index(ModelMap map, HttpServletRequest request, HttpServletResponse response) {
		// 查询菜单按钮权限
		List<com.emm.yixun.common.model.Resources> resourcesList = getPermitBtn(Const.RESOURCES_TYPE_FUNCTION);
		map.put("permitBtn", resourcesList);
		map.put("permitBtnJson", JSONArray.fromObject(resourcesList));
		map.put("menu", getPageData().getString("menu"));
		AreaDto areaDto = new AreaDto();
		areaDto.setParentId(Long.valueOf(0));
		ResponseList<Area> responseAreaList = areaServiceFacade.findByDto(areaDto);
		if (responseAreaList.isSuccess() && null != responseAreaList.getEntity()) {
			map.put("areas", responseAreaList.getEntity());
		} else {
			map.put("areas", new ArrayList<Area>());
		}
		return "/estate/projectFC/list";
    }
    
    /**
	 * 获取流程自定义前缀
	 * @param user
	 * @return
	 */
	public String getProcDefinedPrefix(User user){
		String result = "";
		Response<Merchant> merchantResponse = merchantServiceFacade.findById(user.getMerchantId());
		if(merchantResponse.isSuccess()&&merchantResponse.getEntity()!=null){
			String information = merchantResponse.getEntity().getPhoneInformation();
			com.alibaba.fastjson.JSONArray jsonArray = JSON.parseArray(information);
			for (int i = 0; i < jsonArray.size(); i++) {
				com.alibaba.fastjson.JSONObject jsonObject = jsonArray.getJSONObject(i);
			    String type = jsonObject.getString("type");
			    String status = jsonObject.getString("status");
			    if("99".equals(type) && StringUtils.isNotEmpty(status)){
			    	result = status;
			    }
			}
		}
		return result;
    }
	
	public static void main(String[] args) {
		String information = "[{type:1,status:0},{type:2,status:1},{type:3,status:1},{type:4,status:1},{type:5,status:0},{type:6,status:1},{type:7,status:0},{type:99,status:'FC'}]";
		com.alibaba.fastjson.JSONArray jsonArray = JSON.parseArray(information);
		for (int i = 0; i < jsonArray.size(); i++) {
			com.alibaba.fastjson.JSONObject jsonObject = jsonArray.getJSONObject(i);
		    String type = jsonObject.getString("type");
		    String status = jsonObject.getString("status");
		    	System.out.println(type);
		    	System.out.println(status);
		    	System.out.println("=========================");
		}
	}
}
